<template>
  <div id="Resume">
    <vj-form :cfg-list="cfgList" :after-slot-idx="[cfgList.length-1]" :form.sync="formData">
      <template #form-after-items="{idx}">
        <van-cell class="c-cell" title="作品附件" border>
          <van-uploader max-count="1" v-model="fileList" :after-read="afterRead"/>
        </van-cell>
      </template>
    </vj-form>
    <van-button size="large" type="primary" style="margin-top: 10px" @click="onSubmit">提交</van-button>
  </div>
</template>
<script lang="ts">
import Vue, {ComponentOptions, VueConstructor} from "vue"
import Component from 'vue-class-component'
import VjForm from "@/components/logic/vj-form.vue";
import {PROFILE_FM, PROFILE_FM_SUB, RESUME_FM} from "@/config/forms";
import {requestByGet, requestByPost, requestByPut, requestByUpload} from "@/utils/request";
import {cloneDeep} from "vijay-util";

@Component({
  components: {VjForm}
})
export default class Resume extends Vue implements ComponentOptions<Vue> {
  name = "Resume";
  cfgList = RESUME_FM;
  formData: any = {};
  fileList: any = [];

  async onSubmit() {
    const {id} = this.formData;
    const requestFn = id ? requestByPut : requestByPost;
    await requestFn(`/qqc/qqcResume/${id ? 'edit' : 'add'}`, this.formData);
    this.$toast.success("操作成功！");
    return this.initData();
  }

  async initData() {
    this.formData = await requestByGet(`/qqc/qqcResume/userList`, {userId: sessionStorage.getItem("userId")})
    this.fileList = [{url: this.formData["works"]}]
  }

  created() {
    this.initData();
  }

  async afterRead({file}) {
    this.formData["works"] = await requestByUpload({file});
  }
}
</script>

<style scoped lang="scss">
@import "~assets/common.scss";

#Resume {
}
</style>
